package cxf;

import cn.demoncat.util.webservice.CxfClientUtil;
import cxf.service.TestCxfService;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * CXF配置
 *
 * @author 延晓磊
 * @since 2021年08月19日
 */
@Configuration
public class CxfConfig {

    /**
     * 注册端点
     */
    @Bean
    @Autowired
    public Endpoint cxfEndpoint(Bus bus, TestCxfService testCxfService) {
        EndpointImpl endpoint = new EndpointImpl(bus, testCxfService);
        // 端点路径：/{cxf.path}/test?wsdl
        endpoint.publish("/test");
        return endpoint;
    }

    /**
     * 代理客户端（生成并拷贝服务端wsdl代码）
     */
    @Bean
    public TestCxfService cxfClient(){
        return CxfClientUtil.build(TestCxfService.class, "wsdl", "user", "pwd");
    }
}
